package cn.yes.like;

import cn.yes.like.Animal;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class App1 {
    public static void main(String[] args) throws Exception{
        //Class<?> WW = Class.forName("cn.yes.like.Animal");
        //Object m = WW.newInstance();
        //Method run = WW.getDeclaredMethod("run");
        //System.out.println(run.invoke(m));
        Class<?> MM = Class.forName("cn.yes.like.Animal");
        Object o=MM.newInstance();
        Field[] fields = MM.getDeclaredFields();
        for (int i=0;i<fields.length;i++){
            Field field=fields[i];
            field.setAccessible(true);
            Class<?> type = field.getType();
            if(type.toString().endsWith("String")){
                field.set(o,"花花");
            }
            else if(type.toString().endsWith("Integer")){
                field.set(o,2);
            }
            else if(type.toString().endsWith("Double")){
                field.set(o,10.4);
            }
        }
        Method say=MM.getMethod("say");
        System.out.println(say.invoke(o));
    }
}
